<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">
		<link href=" themes/css/ui.common.css" rel="stylesheet"
			type="text/css" />
		<link href=" themes/css/ui.child.css" rel="stylesheet" type="text/css" />
		<link href=" themes/css/ui.tips.css" rel="stylesheet" type="text/css" />
		<link href=" style/jquery_ui/jquery-ui-1.8.custom.css"
			rel="stylesheet" type="text/css" />
		<link id="skin_css" rel="stylesheet" type="text/css"
			href=" themes/css/ui.c.blue.css"></link>
		<link rel="stylesheet" href=" themes/default/pagination.css"
			type="text/css"></link>
			<link rel="stylesheet" href="themes/css/ui.validation.css" type="text/css"></link>
		<script src=" Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
		<script src=" Scripts/jquery-ui-1.8.custom.min.js"
			type="text/javascript"></script>

		<script src=" Scripts/ui.tips.js" type="text/javascript"></script>
		<script src=" Scripts/ui.default.js " type="text/javascript"
			charset="UTF-8"></script>
		<script src=" Scripts/ui.admincp.js" type="text/javascript"
			charset="UTF-8"></script>
		<script type="text/javascript" src="Scripts/jquery.json-2.2.min.js"></script>
		<script type="text/javascript" src="Scripts/ui.validation.js"></script>
	
		<STYLE type="text/css">
.editorArea {
	display: none;
}
</STYLE>
		<script type="text/javascript" src=" Scripts/ui.dialogFormHelper.js"></script>
		<SCRIPT type="text/javascript">
			$(function(){
				
				$("#dialog").dialog("destroy"); 
				$("#dialog-form").dialog({
				autoOpen: false,
				height: 380,
				width: 500,
				modal: true 
				});
				
				//点击添加按钮
				$('#addGoodsButton').click(function() {   
						$("#dialog-form").dialog({'title':"添加 物资信息"});
						clearInputControlValue("#dialog-form .ui-mainTab");
						 
				     	$('#dialog-form').dialog('open');
				     	 
				});
	            registeTabToggle("#addGoodsCategoryButton", "#cancelAddGoodsCategoryButton");
	            //注册功能按钮事件..
	            registeRowFuncButton();
				$(".numValue").numeral();
				$("#dialog-form").validatingForm({
					submitButtonId:"#SubmitGoodsInfoButton",
					clearErrorTipsTrigger:"#addGoodsButton,.ui-link-edit-button",
					success:submit , // 指向 原来用于提交的方法.// 并且删除 提交按钮注册的 click 代码.
					clearErrorsOnFocus:true, //
					validateOnBlur:true
				});
			});
		 
				function toEditHandler(e)
				{ 
				    var columns = e.data; 
					$("#dialog-form").dialog({'title':"编辑 物资信息"});
					$("#txt_goodsName").val($(columns[1]).text());
					
					var categoryId = $(columns[2]).find(".categoryId").attr("categoryId");
					$("#drl_GoodsType").val(categoryId); 
					
					
					$("#txt_price").val($(columns[3]).text());
					$("#txt_total").val($(columns[4]).text());
					$("#txt_onStore").val($(columns[5]).text());
					$("#txt_Description").val($(columns[6]).text());
					$("#lbl_PublishTime").text($(columns[7]).text());
					$("#goodsId").val(e.entityId);
					$('#dialog-form').dialog('open'); 
					
				}
			function submit(){
			var goodInfo = {
					"goodsName": $.trim($("#txt_goodsName").val()),
					"categoryId":$.trim($("#drl_GoodsType").val()),
					"price":$.trim($("#txt_price").val()),
					"total":$.trim($("#txt_total").val()),
					"description":$.trim($("#txt_Description").val()),
					"goodId":$.trim($("#goodsId").val())
				} ;
				
				var jsonString = $.toJSON(goodInfo);
				var currentPage=$("#currentPage").val();
				var goodId=$("#goodsId").val();
			
				$.post(
				"goodsinfo!add.action",
				{
					goodInfoJsonString: jsonString
				},
				function(data){
					location="goodsinfo.action?currpage="+currentPage+"&goodId="+goodId;
				},
				"json");
			}
			
			function submitAddCategory(){
					var goodsCategoryInfo = {
					"categoryName": $.trim($("#txt_categoryName").val())
					} ;
				
					var jsonString = $.toJSON(goodsCategoryInfo);

					$.post(
					"goodsinfo!addCategory.action",
					{
						goodInfoJsonString: jsonString
					},
					function(data){
						location="goodsinfo.action";
					},
					"json"
					);
				}
			</script>
		<SCRIPT type="text/javascript">
			var searching = false;
				$(function(){
					$("#link_page_prev,#link_page_next").click(function(){
			    		var currentPage = $(this).attr("currentPage");
			    	 
			    		goToPage(currentPage);
			    	}); 
			    	
			    	$("#searchButton").click(function(){
						searching=true;
			    		goToPage(1);
			    	});
			    	
			    	initSearch();
			    	registeRowFuncButton();
				});
				
				function initSearch()
				{
				    $("#txt_noticeTitle").val();
				}
			 
				function goToPage(currentPage)
				{
				    var title = $("#txt_noticeTitle").val();
				    var place =$("#ddl_place").val(); 
				    var cateId=$("#cateId").val();
					var states=$("#states").val();
				     
					location.href = "goodsinfo.action?currpage="+currentPage+"&categoryId="+cateId+"&states="+states+"&goodId=1";
				}
				</SCRIPT>
	
	</head>

	<body>
	 <div class="PageChild_Title">
        <img src=" themes/images/default/icons/archives.png" class="PageChild_Tbtnpic" />
        <span class="PageChild_separate"></span><span class="PageChild_TbtnText">
            <h2>
              物资信息管理</h2>
        </span><span class="PageChild_separate"></span>
        <div id="marker" class="red-tips">
        </div>
        <div class="clear">
        </div>
    </div>
		<div class="PageChild_Where">
			<table style="height: 60px;" border="0" cellpadding="0"
				cellspacing="0">

				<tr>
					<td class="mtd" valign="top">
						按物资类型查询:
						<s:select id="cateId" theme="simple" list="allCateList" listKey="categoryId" listValue="categoryName"  headerKey="-1" headerValue="---全部---" value="categoryId"></s:select>
						按状态查询:
	    				<s:select id="states" theme="simple" list="#{1:'有库存',0:'无库存'}"  label="abc" listKey="key" listValue="value"  headerKey="-1" headerValue="--全部--" value="states"></s:select>
					    <input type="submit" name="btn_Serach" value="搜索" id="btn_Serach" onclick="goToPage(1)" class="o-btn" />
					</td>
				</tr>
				<tr>
					<td>
							<s:if test="count!=null">
								<span id="lbl_list_count">
								 共搜索到 <b>${count}</b> 条符合条件的记录。</span>
							</s:if> 
						<input type="button" id="addGoodsButton" value="添加物资" class="o-btn"/>
					</td>
				</tr>
			</table>
		</div>
		<div class="PageChild_List">
			<table width="100%" border="0" cellspacing="0"
				style="text-align: left">
				<tbody class="PageChild_List_head">
					<tr>
						<td width="16">
							<img src="themes/images/default/icons/pcde_314.png" width="16"
								height="16" />
						</td>
						<td>
							物资名称
						</td>
						<td>
							物资类型
						</td>
						<td>
							价格
						</td>
						<td>
							总数
						</td>
						<td>
							剩余
						</td>
						<td>
							描述信息
						</td>
						<td>
							入库时间
						</td>
						<td class="td_width40">
							编辑
						</td>
						<td class="td_width40">
							删除
						</td>
					</tr>
				</tbody>
				<tbody class="PageChild_List_main" style="text-align: left">
					<s:if test="list != null && list.size != 0">
					<s:iterator value="list" var="item" status="no">
						<!-- 物资类型列表开始 -->
						<tr class='td_no_bord'>
							<td class="td_width25">
								<s:property value="#no.count" />
							</td>
							<td>
								<span>${item.goodName}</span>&nbsp;
							</td>
							<td>
								<span class="categoryId"
									categoryId="${item.goodCategory.categoryId}">
									${item.goodCategory.categoryName}</span>&nbsp;
							</td>
							<td>
								<span>${item.price} </span>&nbsp;
							</td>
							<td>
								<span> ${item.total} </span>&nbsp;
							</td>
							<td>
								<span> ${item.onStore} </span>&nbsp;
							</td>
							<td style="over-flow: hidden; width: 170px;">
								${item.description} &nbsp;
							</td>
							<td>
								<span> ${item.createTime} </span>&nbsp;
							</td>
							<td>
								<a class="ui-link-edit-button" id="sender_${item.goodId}"
									href="javascript:void(0);" state="0" entityId="${item.goodId}">
									<img src="themes/icons/edit.png" title="进行编辑" /> </a> &nbsp;

							</td>
							<td>
								<a href="javascript:;"
									onclick='location="goodsinfo!delete.action?goodId=${item.goodId}&currpage=${currpage }";'><img
										src="themes/icons/delete.png" /> </a>
							</td>
						</tr>
					</s:iterator>
					</s:if><s:else>
						<tr><td colspan="10">无记录</td></tr>
					</s:else>
				</tbody>
			</table>

		</div>
		<div id="divTopPageNavi" class="list_r_title_text3">
<input class="hiddenObject" value="${currpage }" id="currentPage">
			<!--分页导航开始-->
			<s:if test="currpage<=1">
				<span class='list_r_title_text3a'> <img
						src=" themes/images/default/page_up_gray.gif"></img> </span>

			</s:if>
			<s:else>
				<span class='list_r_title_text3a'> <a name="link_page_prev"
					id="link_page_prev" href="javascript:void(0);"
					currentPage="${currpage-1}"> <img
							src=" themes/images/default/page_up.gif"></img> </a> </span>
			</s:else>
			<span class='list_r_title_text3b'> 第${currpage }页/共${totalpage
				}页 </span>
			<s:if test="currpage>=totalpage">
				<span class='list_r_title_text3a'> <img
						src=" themes/images/default/page_down_gray.gif"></img> </span>
			</s:if>
			<s:else>
				<span class='list_r_title_text3a'> <a name="link_page_next"
					id="link_page_next" href="javascript:void(0);"
					currentPage="${currpage+1 }"> <img
							src=" themes/images/default/page_down.gif"></img> </a> </span>
			</s:else>
			<span id="goToPageTextArea"><input type="text"
					class="easyui-numberbox" id="goPageNum" max="${totalpage}" min="1" />
				<input type="button" id="turnToPageButton" value="GO" />
			</span>
			<!--分页导航结束-->
		</div>
		<!-- 弹出层标签 -->

		<div id="dialog-form" style="display: none" title="添加新物资">
			<div class="ui-mainTab">
				<div>
					<input type="text" id="goodsId" class="hiddenObject clearable"
						name="goodInfo.goodId" />
					<table width="100%" class="tb tb2">
						<tbody>
							<tr>
								<td class="mtd">
									物资类型:
								</td>
								<td>
									<s:select list="cateList" emptyOption="选择或者添加分类"
										listKey="categoryId" listValue="categoryName" theme="simple"
										 name="goodInfo.goodCategory.categoryId"
										id="drl_GoodsType"></s:select>
									<input type="button" id="addGoodsCategoryButton" value="添加">
								</td>
								<td width="20">
								</td>
							</tr>
						</tbody>
						<tr>
							<td class="mtd">
								<span id="span_txt_goodsName">物资名称</span>:
							</td>
							<td>
								<input class="control clearable required-field" value="" id="txt_goodsName"
									name="goodInfo.goodName">
							</td>
							<td>
							</td>
						</tr>
						<tr>
							<td class="mtd">
								<span id="span_txt_total">数量</span>:
							</td>
							<td>
								<input class="control clearable numValue required-field" value="" id="txt_total"
									name="goodInfo.total">
							</td>
							<td>
							</td>
						</tr>

						<tr>
							<td class="mtd">
								<span id="span_txt_price">单价</span>:
							</td>
							<td>
								<input class="control clearable numValue required-field" value="" id="txt_price"
									name="goodInfo.price">
							</td>
							<td>
							</td>
						</tr>
						<tr>
							<td class="mtd">
								描述信息:
							</td>
							<td>
								<textarea class="control clearable" rows="4"
									id="txt_Description" style="" name="goodInfo.description"></textarea>
							</td>
							<td>
							</td>
						</tr>
						<tr>
							<td class="mtd">
								入库时间
							</td>
							<td>
								<span id="lbl_PublishTime"></span>
							</td>
						</tr>
						<tr>
							<td>
								&nbsp;
							</td>
							<td>
								<div>
									<input type="button" value="提交" id="SubmitGoodsInfoButton">
									&nbsp;&nbsp;
									<input type="button" name="name" id="cancelAddGoodsInfoButton"
										class="dialogFormCloseButton" dialogForm="#dialog-form"
										value="取消" />
								</div>
							</td>
							<td>
								&nbsp;
							</td>
						</tr>
					</table>
				</div>
			</div>
			<!-- 弹出层结束 -->
			<div id="addGoodsCategoryTab" title="添加物资类型" class="ui-assistantTab"
				style="display: none;">
				<table width="100%" class="tb tb2">
					<tbody>
						<tr>
							<td class="mtd">
								类型名称:
							</td>
							<td>
								<input class="control" type="text" name="name" id="txt_categoryName"  />
							</td>
							<td width="20">
							</td>
						</tr>
					</tbody>
					<tr>
						<td class="mtd">
							&nbsp;
						</td>
						<td>
							<input type="button" name="name" value="添加" onclick='var text= $("#txt_categoryName").val();if($.trim(text).length==0){alert("请输入名称.");$("#txt_categoryName").focus(); return false;} submitAddCategory();'/>
							<input type="button" name="name"
								id="cancelAddGoodsCategoryButton" value="取消" />
						</td>
						<td></td>
					</tr>
				</table>
			</div>
		</div>
	</body>


</html>
